import java.util.*;
import java.math.*;

public class euler027 {
	
	static public void main(String[] params) {
		final int B = 1000000, P = (int)Math.sqrt((double)B) + 1;
		long s = 0;
		int n,m;
		int a,ma;
		int b,mb;
		//Sieve of Eratosthenes
		boolean primes[] = new boolean[B];
		primes[0] = true; primes[1] = true;
		for (int i = 2; i < P; i++) {
			if (!primes[i]) {
				for (int j=2*i; j<primes.length; j+=i) primes[j] = true;
			}
		}
				
		m = 0; ma = 0; mb = 0;
		for (a = -1000; a <= 1000; a++ ) {
			for (b = -1000; b <= 1000; b++) {
				for (n = 0; (n*n + a*n + b > 0) && (primes[n*n + a*n + b]) == false; n++);
				if (n > m) {
					m = n; ma = a; mb = b;
				}
			}
		}
		System.out.println(""+ma*mb);
	}
}

